package com.xmm.view;

import java.util.Map;

import javax.swing.JSplitPane;

import com.xmm.constants.CONSTANTS;
import com.xmm.listener.MouseActionListener;
import com.xmm.model.Artist;

public class MusicSplitPane extends JSplitPane {
	/**
	 * 
	 */
	private static final long serialVersionUID = 535394218798046736L;

	private MusicTree mMusicTree = null;
	private MusicPane mMusicPane = null;
	
	public MusicSplitPane() {
		super();
	
		mMusicTree = new MusicTree();
		add(mMusicTree, JSplitPane.LEFT);
		
		mMusicPane = new MusicPane();
		add(mMusicPane, JSplitPane.RIGHT);

		init();
	}
	
	private void init() {
		mMusicTree.setClickListener(mMusicTreeClickListener);
	}
	
	private MouseActionListener mMusicTreeClickListener = new MouseActionListener() {

		@Override
		public void doSingleClick(Map<String, Object> info) {
			if(info == null) return;
			
			mMusicPane.setTitle((String)info.get(CONSTANTS.TRACK_TITLE_NAME));
			
			Object obj = info.get(CONSTANTS.TRACK_ARTIST_NAME);
			if(obj != null) {
				mMusicPane.setArtist(((Artist)obj).toString());
			} else {
				mMusicPane.setArtist(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_LENGTH_NAME);
			if(obj != null) {
				mMusicPane.setLength(String.valueOf((Long)obj));
			} else {
				mMusicPane.setLength(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_COMMENT_NAME);
			if(obj != null) {
				mMusicPane.setComment((String)obj);
			} else {
				mMusicPane.setComment(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_DATE_NAME);
			if(obj != null) {
				mMusicPane.setDate((String)obj);
			} else {
				mMusicPane.setDate(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_RATING_NAME);
			if(obj != null) {
				mMusicPane.setRating(String.valueOf((Double)obj));
			} else {
				mMusicPane.setRating(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_SIZED_NAME);
			if(obj != null) {
				mMusicPane.setSized(String.valueOf((Long)obj));
			} else {
				mMusicPane.setSized(null);
			}
			
			obj = info.get(CONSTANTS.TRACK_ABLUM_NAME);
			if(obj != null) {
				mMusicPane.setAblum((String)obj);
			} else {
				mMusicPane.setAblum(null);
			}
		}

		@Override
		public void doDoubleClick(Map<String, Object> info) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void doRightClick(Map<String, Object> info) {
			// TODO Auto-generated method stub
			
		}

	};
}
